<template>
  <el-dialog
    v-model="visible"
    title="批量忽略"
    width="600px"
    :close-on-click-modal="false"
  >
    <div class="batch-ignore-content">
      <div class="info-section">
        <p>已选择 <strong>{{ selectedCount }}</strong> 个资产进行批量忽略</p>
        <p class="warning-text">⚠️ 忽略后的资产将不再显示在待处理列表中</p>
      </div>

      <el-form ref="formRef" :model="form" label-width="100px">
        <el-form-item label="忽略原因">
          <el-input
            v-model="form.ignore_reason"
            type="textarea"
            :rows="4"
            placeholder="请输入忽略原因（可选）"
          />
        </el-form-item>
      </el-form>
    </div>

    <template #footer>
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="warning" :loading="submitting" @click="handleSubmit">
        确认忽略
      </el-button>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, computed, watch } from "vue";
import type { FormInstance } from "element-plus";

const props = defineProps({
  modelValue: { type: Boolean, default: false },
  selectedCount: { type: Number, default: 0 },
});

const emit = defineEmits<{
  (e: "update:modelValue", value: boolean): void;
  (e: "confirm", data: { ignore_reason?: string }): void;
}>();

const visible = computed({
  get: () => props.modelValue,
  set: (value: boolean) => emit("update:modelValue", value),
});

const formRef = ref<FormInstance>();
const submitting = ref(false);
const form = ref({
  ignore_reason: "",
});

// 监听弹窗打开，初始化表单
watch(visible, (newVal) => {
  if (newVal) {
    form.value.ignore_reason = "";
  }
});

// 提交
const handleSubmit = () => {
  const submitData: any = {};
  if (form.value.ignore_reason) {
    submitData.ignore_reason = form.value.ignore_reason;
  }
  emit("confirm", submitData);
};

// 取消
const handleCancel = () => {
  emit("update:modelValue", false);
};
</script>

<style scoped lang="scss">
.batch-ignore-content {
  .info-section {
    margin-bottom: 20px;
    padding: 10px;
    background-color: #f5f7fa;
    border-radius: 4px;

    p {
      margin: 0 0 8px 0;
      color: #606266;

      &:last-child {
        margin-bottom: 0;
      }

      strong {
        color: #409eff;
      }
    }

    .warning-text {
      color: #e6a23c;
      font-size: 13px;
    }
  }
}
</style>

